package com.controller;

import com.entity.param.MySQLSchemaParam;
import com.entity.vo.MySqlTablesVo;
import com.service.MySqlSchemaService;
import com.util.R;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

@Slf4j
@Api(tags = "MySQL-数据库信息查询")
@RequestMapping("/schema")
@RestController
public class SchemaController {

    @Resource
    private MySqlSchemaService mySqlSchemaService;

    @ApiOperation(value = "表查询-按大小排序")
    @GetMapping("/showTables")
    public R<List<MySqlTablesVo>> showTables(String databaseName){
        List<MySqlTablesVo> tables = mySqlSchemaService.schemaTables(databaseName);
        log.info("tables: {}",tables);
        return R.ok(tables);
    }

    @ApiOperation(value = "数据查询")
    @GetMapping("/queryRecords")
    public R<List<Map<String, Object>>> queryRecords(MySQLSchemaParam param){
        List<Map<String, Object>> maps = mySqlSchemaService.queryList(param);
        return R.ok(maps);
    }

}
